/**
 * Created by james on 2017/9/21.
 */
export default {
  formatTime(time, format = 'yyyy-MM-dd HH:mm:ss') {
    if (time == '') return '';
    var t = new Date(time);
    var tf = function (i) {
      return (i < 10 ? '0' : '') + i
    };
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
      switch (a) {
      case 'yyyy':
        return tf(t.getFullYear());
      case 'MM':
        return tf(t.getMonth() + 1);
      case 'mm':
        return tf(t.getMinutes());
      case 'dd':
        return tf(t.getDate());
      case 'HH':
        return tf(t.getHours());
      case 'ss':
        return tf(t.getSeconds());
      }
    })
  },
  arrTimeFormat(data) {
    // element 默认值检测
    if (typeof data == 'undefined') return [null, null];
    if (data[0] == null) return [null, null];
    if (data[0] == '1970-01-01 08:00:00') return [null, null];
    return data.map((item) => {
      return this.formatTime(item);
    }, this)

  },
  formatFloat(f, digit) { // 高精度计算
    let m = Math.pow(10, digit);
    return parseInt(f * m, 10) / m;
  },
  getCurrentRouter(array) {
    return array[3]['redirect'];
  }
}
